/**
 * 产品（添加|修改）product.js
 * 版本号： v1.0.0
 */
$(function () {
    //限制字段输入长度
    limitFieldLength();
    //绑定供应商列表
    bindCombo_supplierList("supId")
    //点击保存按钮
    $('#optionProduct').bind('click', function(){
        if($("#product_form").form("validate")){
            preventSubmit('product_form','optionProduct');
            var params = $("#product_form").serialize();
            $.ajax({
                url: CONTEXT_PATH + "/product/save.do",
                data: params,
                type: "post",
                dataType:'json',
                success: function (data) {
                    var url = CONTEXT_PATH + "/product/index.do";
                    saveJump(data,url);
                }
            })
        }
    })
})

/**
 * 供应商bind事件
 * @param deviceControl
 */
function bindCombo_supplierList(supplierControl) {
    var companyId = $("#companyId_").val();
    $.ajax({
        url: CONTEXT_PATH + "/supplier/getSupplierList.do",
        data:{
            "companyId":companyId
        },
        type: "get",
        success: function (data) {
            var supplierCombo = [];
            for (var i = 0; i < data.length; i++) {
                supplierCombo.push({"text": data[i].supName, "value": data[i].supId});
            }
            $("#" + supplierControl).combobox("loadData", supplierCombo);
            $("#" + supplierControl).combobox({
                required:true,
                onSelect: function(rec){
                    $('#supId_').val(rec.value);
                }
            });
            var supId = $('#supId_').val();
            if(supId){
                $("#" + supplierControl).combobox("setValue", supId);
            }else{
                $("#" + supplierControl).combobox("setValue", '');
            }
        }
    })
}






